package com.example.couponprovider.dubbo;

import com.example.couponprovider.constants.CouponStatus;
import com.example.couponprovider.domain.Coupon;
import com.example.couponprovider.tcc.ICouponAction;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.apache.dubbo.config.annotation.DubboService;
import org.example.api.CouponApiTcc;
import org.example.dto.CouponDto;
import org.example.response.R;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Kong
 * @date 2021-9-15 14:38
 */
@DubboService
public class CouponDubboServiceTcc implements CouponApiTcc {
    @Autowired
    private ICouponAction couponAction;
    @Override
    public R issueCoupon(CouponDto dto) {
        Coupon coupon = new Coupon();
        coupon.setAccount(1);
        coupon.setCouponId(1);
        coupon.setUserId(1);
        coupon.setState(CouponStatus.INITIAL.getValue());
        couponAction.prepareCreateOrder(new BusinessActionContext(),coupon);
        return R.Builder.getInstance().buildOk().build();
    }
}
